<template>
<div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- home分类模块 -->
        <home-banner></home-banner>
        <!-- home banner轮播图模块 -->
        <home-category></home-category>
        <!-- home Panel 新鲜好物 -->
        <home-panel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
          <template #right>
             <xtx-more />
          </template>
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in newLIst" :key="item.id">
                <RouterLink :to="`/good/${item.id}`">
                  <img :src="item.picture" alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
        <!-- Home Hot 人气好物 -->
        <home-panel title="人气推荐" subTitle="人气推荐 品质靠谱">
          <template #main>
            <ul class="goods-list">
              <li v-for="item in hotList" :key="item.id">
                <RouterLink to="/">
                  <!-- v-lazy-img 全局自定义图片懒加载指令 -->
                  <img v-lazy-img="item.picture" />
                  <p class="name">{{ item.title }}</p>
                  <p class="price">{{ item.alt }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>

      </div>
    </div>
  </div>

</template>

<script>
import HomeBanner from './components/home-banner.vue'
import HomeCategory from './components/home-category.vue'
import HomePanel from '@/views/Home/components/home-panel'
import { findNew, findHot } from '@/api/home'

import { ref } from 'vue'
export default {
  name: 'home-index',
  components: {
    HomeBanner,
    HomeCategory,
    HomePanel
  },
  setup () {
    // 新鲜好物
    const newLIst = ref([])
    async function fetchNewList () {
      const res = await findNew()
      newLIst.value = res.data.result
    }
    fetchNewList()

    const hotList = ref([])
    async function fethotList () {
      const res = await findHot()
      hotList.value = res.data.result
    }
    fethotList()
    return { newLIst, hotList }
  }

}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
